/*** Class Name: iFulfillQueryHandlerTest
 * Author: Accenture
 * Date: 10-Nov-2011
 * Requirement/Project Name: iFulfill
 * Requirement Description: Test class for iFulfillQueryHandler
 **/

@istest
private  class iFulfillQueryHandlerTest
{
  /**
  *  Test method 
  */
    
  static testMethod void testQueryHandler() 
  {
  
         Profile p = [select id from profile where name='System Administrator'];         
         User u = new User(alias = 'sysad', email='sysadmin@accenture.com',emailencodingkey='UTF-8', lastname='Tes12', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='testad123@testorg.com');           
        Insert u; 
        Account acc = new Account(name= 'xyx');
        insert acc;   
         Fullfilment_Item__c FI4 = new Fullfilment_Item__c(Account__c = acc.id,Main_Listing_Phone_Number__c = '104560',Listed_Name__c ='XIne',Heading_Name__c ='Test Get grouped',Item_Id__c = 'Item id123' ,Product_Code__c ='p1',UDAC__c ='Udac1',Region__c = 'Out-of-Region',Transaction_Type__c ='New', ownerid = u.id,group_id__c =2);
         insert FI4 ;
          
           Fullfilment_Item__c F = [select ownerID from  Fullfilment_Item__c  where id = :FI4.id ];
           F.ownerID = u.id;
           update f;
        Query_Request__c qr = new  Query_Request__c(Fulfillment_Item__c = FI4.ID,Request_Comments__c='Test Comment',Request_Reason__c= 'Reason 1',UDAC_Description__c='Udac Testing');

        insert qr;
        
        Queries__c  qry = new  Queries__c(  Query_Request_ID__c = qr.id ,Query_code__c='0845 � PAS � PAS Appointment not setUndo',Query_SLA__c =14);
        insert qry;
        
         Queries__c  qry1 = [select Query_Status__c,Unresolved_Reasons__c  from Queries__c where id =:qry.id ];
         qry1.Query_Status__c='Unresolved';
          qry1.Unresolved_Reasons__c ='Duplicate';
          
         update qry1;
        
        
        List<Queries__c> queryList = new List<Queries__c>();
        queryList.add(qry);
        queryList.add(qry1);
        
        iFulfillQueryHandler.updateEmailTemplate(queryList);

        
    }

  
    static testMethod void testNewIRQuery()
    {
      
        Profile p = [select id from profile where name='System Administrator'];         
        User mgrUser  = new User(alias = 'sysmgr', email='sysadmin@accenture.com',emailencodingkey='UTF-8', lastname='testMgr', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='manager@testorg.com');           
        insert mgrUser;
        User u = new User(alias = 'sysad', email='sysadmin@accenture.com',emailencodingkey='UTF-8', lastname='Tes12', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='testad123@testorg.com' ,managerID= mgrUser.id);           
        Insert u; 
        Account acc = new Account(name= 'xyx');
        insert acc;   
        Fullfilment_Item__c FI4 = new Fullfilment_Item__c(Product_Family__c = 'Banner' , Account__c = acc.id,Main_Listing_Phone_Number__c = '104560',Listed_Name__c ='XIne',Heading_Name__c ='Test Get grouped',Item_Id__c = 'Item id123' ,Product_Code__c ='p1',UDAC__c ='Udac1',Region__c = 'region1',Transaction_Type__c ='New', ownerid = u.id,group_id__c =2);
        insert FI4 ;
        Query_Reason_Code__c qryReasonCode  = new Query_Reason_Code__c( Product_Family__c = 'Banner' , Reason_Code__c = 'Dead Link');
        insert   qryReasonCode;
        Fullfilment_Item__c F = [select ownerID from  Fullfilment_Item__c  where id = :FI4.id ];
        F.ownerID = u.id;
        update f;
        
        Query_Request__c qr = new  Query_Request__c(Fulfillment_Item__c = FI4.ID,Request_Comments__c='Test Comment',Request_Reason__c= 'Reason 1');
        insert qr;
        
        Queries__c  qry = new  Queries__c(  Query_Request_ID__c = qr.id ,Query_code__c='0845 � PAS � PAS Appointment not setUndo' , Override_Sales_Rep__c= true , Sales_Rep_Name1__c =u.id );
        insert qry;

         PageReference pageRef = Page.ifulfillOORCreateQuery;
         ApexPages.StandardController ctrl = new ApexPages.StandardController(qry );
         ifulfillNewIRQuery newIRQuery = new ifulfillNewIRQuery(ctrl);
         newIRQuery .save();
         newIRQuery .initlizeQueryReasonCode();

       
    }
    
    static testMethod void testQueryRedirectTest()
    {
      
        Profile p = [select id from profile where name='System Administrator'];         
        User u = new User(alias = 'sysad', email='sysadmin@accenture.com',emailencodingkey='UTF-8', lastname='Tes12', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='testad123@testorg.com');           
        Insert u; 
        Account acc = new Account(name= 'xyx');
        insert acc;   
        Fullfilment_Item__c FI4 = new Fullfilment_Item__c(Account__c = acc.id,Main_Listing_Phone_Number__c = '104560',Listed_Name__c ='XIne',Heading_Name__c ='Test Get grouped',Item_Id__c = 'Item id123' ,Product_Code__c ='p1',UDAC__c ='Udac1',Region__c = 'region1',Transaction_Type__c ='New', ownerid = u.id,group_id__c =2);
        insert FI4 ;
          
        Fullfilment_Item__c F = [select ownerID from  Fullfilment_Item__c  where id = :FI4.id ];
        F.ownerID = u.id;
        update f;
        
        Query_Request__c qr = new  Query_Request__c(Fulfillment_Item__c = FI4.ID,Request_Comments__c='Test Comment',Request_Reason__c= 'Reason 1');
        insert qr;
        
        Queries__c  qry = new  Queries__c(  Query_Request_ID__c = qr.id ,Query_code__c='0845 � PAS � PAS Appointment not setUndo');
        insert qry;

         
         
         PageReference pageRef = Page.iFulfillQueryRedirect;
         ApexPages.StandardController ctrl = new ApexPages.StandardController(qry );
         iFulfillQueryRedirectCtrl qryRedirectCtrl = new iFulfillQueryRedirectCtrl(ctrl);
          qryRedirectCtrl.pageRedirect();
       
    }
}